﻿app.factory('MoviesService', function ($http, $q) {
    var myActors = [];
    //Read Actors Call
    function getAllActors() {
        var def = $q.defer();     //setting up the promise
        $http({
            url: '/api/allactors',
            method:'GET'
        }).success(function (data) {
            myActors = [];
            console.log("data return:", data)   
            for (var i in data) {
                console.log("-- names:", data[i].name)
                myActors.push(data[i])
            }
            def.resolve(data);
        }).error(function (data) {
            def.reject();
        })
        return def.promise;
    }

    function doDelete(id) {
        var def = $q.defer();
        $http({
            url: '/api/delactor/' + id,
            method: 'DELETE'
        }).success(function () {
            def.resolve();
        }).error(function () {
            def.reject();
        })
        return def.promise;
    }



    return {
        getAllActors: getAllActors,
        myActors: myActors,
        doDelete: doDelete
    }
});